package api

import (
	"fmt"
	"vblog/apps/user"
	"vblog/ioc"

	"github.com/gin-gonic/gin"
)

type Handler struct {
	svc user.Service
}

// 让他从Ioc中获取依赖的对象
func (h *Handler) Init() error {
	var ok bool
	h.svc, ok = ioc.GetController(user.AppName).(user.Service)
	if ok {
		return nil
	} else {
		return fmt.Errorf("%v is not a blog.Service", ioc.GetController(user.AppName))
	}
}

func (h *Handler) Name() string {
	return user.AppName
}

func (h *Handler) RegistryApi(r gin.IRouter) {
	r.POST("/login", h.Login)
	r.DELETE("/logout", h.Logout)
}

func init() {
	ioc.RegistryHttpApi(&Handler{})
}
